/*
 * pthread_mutex_f.h
 *
 *  Created on: Aug 14, 2012
 *      Author: lucid
 */

#ifndef __THREAD_MUTEX_F_H__
#define __THREAD_MUTEX_F_H__

#include <pthread.h>

class mutexf_t
{
protected:
	pthread_mutex_t		_mtx;

public:
	mutexf_t();
	~mutexf_t();

	int lock();
	int timedlock(const struct timespec *abstime);
	int unlock();

	int trylock();
	int is_locked();

	//operator pthread_mutex_t()	{	return _mtx;	}
	operator pthread_mutex_t&();
};

//this class is use locally only,so,his name is mutex[L]f_t
//define a local mutexlf_t and pass a mutex or mutexf_t to it
//before use mutexlf_t,remember to initial the mutex first.
class mutexlf_t
{
protected:
	pthread_mutex_t&	_mtx;

public:
	mutexlf_t(pthread_mutex_t& m);
	virtual ~mutexlf_t();
};


#endif /* __THREAD_MUTEX_F_H__ */
